Store locations as GFile
authorMatthias Clasen <mclasen@redhat.com>
Fri, 24 Jul 2015 19:29:51 +0000 (15:29 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 27 Jul 2015 12:07:38 +0000 (08:07 -0400)
It is a bit pointless to have the file chooser get a uri from an
existing GFile to put in the query, only to have some of the search
engines reconstruct a GFile from it.

gtk/gtkfilechooserwidget.c
gtk/gtkquery.c
gtk/gtkquery.h
gtk/gtksearchenginesimple.c
gtk/gtksearchenginetracker.c

index 978608d3fb945146126821f7c2fc7b24518672be..4b0a2d71372e5e2f107fe6f315783215b124d620 100644 (file)
@@ -7208,10 +7208,7 @@ search_start_query (GtkFileChooserWidget *impl,
   file = gtk_places_sidebar_get_location (GTK_PLACES_SIDEBAR (priv->places_sidebar));
   if (file)
     {
-      gchar *location;
-      location = g_file_get_uri (file);
-      gtk_query_set_location (priv->search_query, location);
-      g_free (location);
+      gtk_query_set_location (priv->search_query, file);
       g_object_unref (file);
     }
 
index bc81b7da3ee2dccebfac0c047ad0de2d2db41744..d7eca90773d70b7d9e2217690deefc5efec74619 100644 (file)
@@ -27,7 +27,7 @@
 struct _GtkQueryPrivate
 {
   gchar *text;
-  gchar *location_uri;
+  GFile *location;
   GList *mime_types;
   gchar **words;
 };
@@ -41,8 +41,8 @@ finalize (GObject *object)
 
   query = GTK_QUERY (object);
 
+  g_clear_object (&query->priv->location);
   g_free (query->priv->text);
-  g_free (query->priv->location_uri);
   g_strfreev (query->priv->words);
 
   G_OBJECT_CLASS (gtk_query_parent_class)->finalize (object);
@@ -87,18 +87,17 @@ gtk_query_set_text (GtkQuery    *query,
   query->priv->words = NULL;
 }
 
-const gchar *
+GFile *
 gtk_query_get_location (GtkQuery *query)
 {
-  return query->priv->location_uri;
+  return query->priv->location;
 }
 
 void
-gtk_query_set_location (GtkQuery    *query,
-                        const gchar *uri)
+gtk_query_set_location (GtkQuery *query,
+                        GFile    *file)
 {
-  g_free (query->priv->location_uri);
-  query->priv->location_uri = g_strdup (uri);
+  g_set_object (&query->priv->location, file);
 }
 
 static gchar *
index 50275059150dda24850ca3a2b0b10c7a82ed72c7..0aa5ff97409b8d30f8a0750758f5eb1be3568237 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef __GTK_QUERY_H__
 #define __GTK_QUERY_H__
 
-#include <glib-object.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -57,9 +57,9 @@ const gchar *gtk_query_get_text       (GtkQuery    *query);
 void         gtk_query_set_text       (GtkQuery    *query,
                                        const gchar *text);
 
-const gchar *gtk_query_get_location   (GtkQuery    *query);
+GFile       *gtk_query_get_location   (GtkQuery    *query);
 void         gtk_query_set_location   (GtkQuery    *query,
-                                       const gchar *uri);
+                                       GFile       *file);
 
 gboolean     gtk_query_matches_string (GtkQuery    *query,
                                        const gchar *string);
index def577a5bf7891b55f9035941b96b4e4b5047d4f..d61bb3059d0631011b302c273700e9d16e7d3838 100644 (file)
@@ -92,7 +92,6 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
                        GtkQuery              *query)
 {
   SearchThreadData *data;
-  const gchar *uri;
   GFile *location;
 
   data = g_new0 (SearchThreadData, 1);
@@ -101,9 +100,9 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
   data->directories = g_queue_new ();
   data->query = g_object_ref (query);
   data->recursive = _gtk_search_engine_get_recursive (GTK_SEARCH_ENGINE (engine));
-  uri = gtk_query_get_location (query);
-  if (uri != NULL)
-    location = g_file_new_for_uri (uri);
+  location = gtk_query_get_location (query);
+  if (location)
+    g_object_ref (location);
   else
     location = g_file_new_for_path (g_get_home_dir ());
   g_queue_push_tail (data->directories, location);
index 29edb7f207ca32e69aef73e79b9ed50dc1adee32..7c4e063282ebdf4664e211929079705f44294b2c 100644 (file)
@@ -321,7 +321,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
 {
   GtkSearchEngineTracker *tracker;
   const gchar *search_text;
-  const gchar *location_uri;
+  GFile *location;
   GString *sparql;
   gboolean recursive;
 
@@ -340,7 +340,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
     }
 
   search_text = gtk_query_get_text (tracker->query);
-  location_uri = gtk_query_get_location (tracker->query);
+  location = gtk_query_get_location (tracker->query);
   recursive = _gtk_search_engine_get_recursive (engine);
 
   sparql = g_string_new ("SELECT nie:url(?urn) "
@@ -360,8 +360,9 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
   sparql_append_string_literal_lower_case (sparql, search_text);
   g_string_append (sparql, ")");
 
-  if (location_uri)
+  if (location)
     {
+      gchar *location_uri = g_file_get_uri (location);
       g_string_append (sparql, " && ");
       if (recursive)
         g_string_append (sparql, "tracker:uri-is-descendant(");
@@ -369,6 +370,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
         g_string_append (sparql, "tracker:uri-is-parent(");
       sparql_append_string_literal (sparql, location_uri, FALSE);
       g_string_append (sparql, ",nie:url(?urn))");
+      g_free (location_uri);
     }
 
   g_string_append (sparql, ")");